home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
stdio
/
c
/
filbuf
< prev
next >
Wrap
Text File
|
1996-11-09
|
1KB
|
63 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/filbuf,v $
* $Date: 1996/05/06 09:01:34 $
* $Revision: 1.2 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: filbuf,v $
* Revision 1.2 1996/05/06 09:01:34 unixlib
* Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
* Saved for 3.7a release.
*
* Revision 1.1 1996/04/19 21:32:42 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: filbuf,v 1.2 1996/05/06 09:01:34 unixlib Rel $";
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
__STDIOLIB__
int
__filbuf (register FILE * f)
{
register int n, b, g = f->flag;
register unsigned char *a;
if ((g & (_IOREAD | _IOERR | _IOEOF)) != _IOREAD)
return (-1);
b = (g & _IONBF) ? 1 : f->bufsiz;
if (!(a = f->i_base))
{
if (!(a = f->i_base = malloc (b + 1)))
{
f->flag = g | _IOERR;
return (-1);
}
}
++a; /* for ungetc() */
if ((n = read (f->fd, a, b)) <= 0)
{
f->flag |= ((n) ? _IOERR : _IOEOF);
f->i_cnt = 0;
f->i_ptr = a;
return (-1);
}
f->pos += n;
f->i_cnt = n - 1;
f->i_ptr = a + 1;
return (*a);
}